package com.ysu.zyw.fk.dds;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NamedThreadLocal;

/**
 * DynamicDataSourceKeyHolder is a wrapper of a threadLocal, when an request come and the
 * aspect capture the request, then the aspect inject an data source key into DynamicDataSourceKeyHolder,
 * then this thread go through into logic, when this thread called getConnection method, then method get
 * first find DynamicDataSource and asked for a real data source, then get a connection from real data source.
 * <p>
 * Created by ZeRur on 2016/1/19.
 *
 * @author yaowu.zhang
 */
public class DynamicDataSourceKeyHolder {

    private static final ThreadLocal<String> dataSourceKeyHolder = new NamedThreadLocal<>("dataSourceKeyHolder");

    public static final String get() {
        return dataSourceKeyHolder.get();
    }

    public static final void set(String dataSourceKey) {
        dataSourceKeyHolder.set(dataSourceKey);
    }

}
